package com.athuahua.spzx.controller;

import com.athuahua.spzx.entity.Category;
import com.athuahua.spzx.entity.ProductSku;
import com.athuahua.spzx.service.CategoryService;
import com.athuahua.spzx.service.ProductSkuService;
import com.athuahua.spzx.utils.Result;
import com.athuahua.spzx.vo.h5.IndexVo;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: huahua
 * @Date: 2024/8/9 0009
 * @Time: 16:19
 * @Description:
 */
@Tag(name = "首页接口管理")
@RestController
@RequestMapping("/api/product/index")
@Slf4j
public class IndexController {

    @Resource
    private CategoryService categoryService;

    @Resource
    private ProductSkuService productSkuService;


    @GetMapping
    @Cacheable(cacheNames = "c_category_product_index")
    public Result<IndexVo> index(){
        log.info("首页查询一级分类和热销商品");
        //返回一级分类
        List<Category> categoryList = categoryService.selectOneCategory();;


        //返回销量最高的前十个商品
        List<ProductSku> productSkuList = productSkuService.selectProductSkuBySal();


        IndexVo indexVo = new IndexVo();
        indexVo.setCategoryList(categoryList);
        indexVo.setProductSkuList(productSkuList);

        return Result.success(indexVo);
    }

}
